<?php

namespace App\Http\Controllers\home;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\URL;
use App\Http\Controllers\UserController;
use Illuminate\Support\Facades\Storage;
class IndexController extends Controller
{
    //
    public function upload(Request $request){
//        echo asset('storage/file.txt');die;/
//        $contents = Storage::get('/public/file2.txt');
//        echo $contents;die;
//        return Storage::download('/public/file2.txt', 'dads.txt', ['n'=>'n']);
//        $url = Storage::url('banner1.jpg');echo $url;die;

        if ($request->hasFile('file') && $request->file('file')->isValid()) {
            //
            $path = $request->file('file')->storeAs(
                'images', 'success.'.$request->file('file')->extension()
            );
            return $path;
        }else{
            return 1;
        }
    }
    public function index(Request $request){
        echo storage_path('/images/nn1.png');
        $files = Storage::files('');
        $files = Storage::allFiles('');
        dump($files);
        die;
        return action([UserController::class, 'index']);
        $url =  URL::temporarySignedRoute(
            'profile', now()->addMinutes(30), ['user' => 1]
        );
//        return URL::signedRoute('profile', ['user' => 1]);
        return redirect($url);
        $uri = $request->path();
        echo $uri.'<Br>';
        $url = $request->url();
        echo $url.'<br>';
        $fullUrl = $request->fullUrl();
        echo $fullUrl.'<br>';
        $method = $request->method();
        echo $method.'<br>';
        if ($request->is('home/*')) {
            echo 'home';
        }else{
            echo 'admin';
        }
        dump($request);die;
        $id = $request->input('id');
        dump($id);die;
        return view('home.index.index');
    }
    public function main(Request $request){
        $i = 0;
        $max = 0;
        $s = 'dfsafsdfa';
        $len = mb_strlen($s);
        $arr = [];
        for($j=0;$j<$len;$j++){
            $str = substr($s,$j,1);
            echo $str.'<br>';
            if(!in_array($str,$arr)){
                ++$i;
                if($i > $max){
                    $max = $i;
                }
            }else{
                $i = 0;
            }
            $arr[] = $str;
        }
        echo $max;die;
        echo $request->input('name','default');
        echo '<br>';
        dump($request->all());
        echo '<br>';
        echo $request->name.'<br>';
        dump($request->boolean('archived'));
        echo '<br>';
        $input = $request->only(['username', 'password']);
        dump($input);
        echo '<br>';
        $input = $request->except('credit_card');
        dump($input);
        echo '<br>';
    }
    public function ses(Request $request){
        dump($request->old('username'));
        return view('home/index/index');
    }
}
